package com.eras.shoes.utils

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.eras.shoes.R

class ToastUtils {

    fun show(context: Context, text: String?) {
        val toast = Toast(context)
        val layoutInflater =
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val view: View = layoutInflater.inflate(R.layout.layout_toast, null)
        val textView = view.findViewById<TextView>(R.id.tv_toast_text)
        textView.text = text
        toast.setGravity(Gravity.BOTTOM, 0, 100) // 水平偏移0px，垂直偏移0px
        toast.duration = Toast.LENGTH_SHORT
        toast.setView(view)
        toast.show()
    }

    fun showGravity(context: Context, text: String?, sGravity: Int) {
        val toast = Toast(context)
        val layoutInflater =
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val view: View = layoutInflater.inflate(R.layout.layout_toast, null)
        val textView = view.findViewById<TextView>(R.id.tv_toast_text)
        textView.text = text
        toast.setGravity(sGravity, 0, 0) // 水平偏移0px，垂直偏移0px
        toast.duration = Toast.LENGTH_LONG
        toast.setView(view)
        toast.show()
    }

}